﻿/**
 * ...
 * @author sminutoli
 */
import com.dmotiko.general.*
import com.dmotiko.lib.TimerMovie;
import com.dmotiko.prune.*
import mx.transitions.easing.Regular;
import mx.transitions.easing.Strong;
import mx.transitions.Tween;
import mx.utils.Delegate;
 
class CampaignPhotoBar extends SiteBar
{
	
	public static var FOTOS:String = "campaignbar_fotos";
	public static var GACETILLA:String = "campaignbar_gacetilla";
	
	private var timer:MovieClip;
	private var bFlag:Boolean;
	private var back:MovieClip;
	
	private function initClip():Void {
		super.initClip();
		
		timer = TimerMovie.createTimer(this);
		
		sLink = "CampaignBtn";
		nSpace = 10;
			
		setData( [ 
			{ src: "mini1" , value: 2 }, 
			{ src: "mini2" , value: 3 }, 
			{ src: "mini3" , value: 4 }, 
			{ src: "mini4" , value: 5 }, 
			{ src: "mini5" , value: 6 }, 
			{ src: "mini6" , value: 7 }
			
		] );
		section_changed( { section: Site.getApp().getSection() } );
	}
	
	public function onMouseMove():Void {
		if ( !bFlag ) return;
		if ( Site.getApp().getSection() != SiteSections.CAMPAIGN ) return;
		if ( !bFlag && ( Site.getApp().getSection() != SiteSections.CAMPAIGN || bShowing ) ) return;
				
		if ( bShowed && _xmouse < -150 ) {
			if ( !bShowed ) return;
			hide();
		
		} else if( !bShowed && _xmouse > -150 ) {
			if ( bShowed ) return;
			show();
		
		}
	}
	
	private function refreshData():Void {
		if( !back ) back = attachMovie( "CampaignBack", "back", this.getNextHighestDepth() );
		else back = attachMovie( "CampaignBack", "back", back.getDepth() );
		
		back._alpha = 0;
		back._x = -10;
		back._y = -130;
		
		super.refreshData();
		
	}
	
	public function show():Void {
		super.show();
		registerTween("backFade", new Tween( back, "_alpha", Regular.easeOut, back._alpha, 100, 0.5, true) );
	}
	
	public function hide():Void {
		super.hide();
		registerTween("backFade", new Tween( back, "_alpha", Regular.easeOut, back._alpha, 0, 0.5, true) );
	}
	
	private function tweenFinished( key:String, tween:Tween):Void {
		if ( key.indexOf("fadeBtn") > -1 && btns[0]._alpha > 0 ) {
			bShowing = false;
			timer.startTimer( { bind:this, listener: timer_complete, delay: 5000 } );
			showEnd();
						
		} else if ( key.indexOf("fadeBtn") > -1 && btns[0]._alpha == 0 ) {
			bShowing = false;
			for ( var btn in btns ) { btn._visible = false };			
			hideEnd();
		}
	}
	
	private function timer_complete():Void
	{
		if ( !bFlag ) bFlag = true;
		if( bShowed && _xmouse < -150 ) hide();
	}
	
	private function section_changed(e):Void {
		if ( e.section == SiteSections.CAMPAIGN ) {
			_x = Site.getApp().getClips().get10years()._x;
			_y = Site.getApp().getClips().get10years()._y + Site.getApp().getClips().get10years()._height + 35;
			btns[0].onRelease();
			bFlag = false;
			return;
			
		} else {
			hide();
		}
	}
	
	
	private function btn_changed( e ):Void 
	{
		super.btn_changed(e);		
		MainContent(Site.getApp().getClips().getMainContent()).getContent().showPhoto( e.data.value );
	}
	
}